package br.senac.sp.persistence.test.example;

import br.senac.sp.persistence.AbstractRelationalDBMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class UserMapper extends AbstractRelationalDBMapper<User, Long> {

    public UserMapper() {
        super("USER");
    }

    @Override
    protected User getObjectFromRecord(Long id, ResultSet record) throws SQLException {
        User user = new User();
        user.setId(id);
        user.setName(record.getString("NAME"));
        user.setLogin(record.getString("LOGIN"));
        return user;
    }

    @Override
    protected Map<String, Object> getInfoFromObject(User entity) {
        Map<String, Object> info = new HashMap<String, Object>();
        info.put("LOGIN", entity.getLogin());
        info.put("NAME", entity.getName());
        return info;
    }

    @Override
    protected Long getIdFromObject(User user) {
        return user.getId();
    }

    @Override
    protected String getUniqueIdentifierArguments() {
        return "ID";
    }
}
